<?php
/**
 * @see ZendX_JQuery_View_Helper_UiWidget
 */
require_once "ZendX/JQuery/View/Helper/UiWidget.php";

/**
 * Помощник вида, реализующий выбор тегов с использованием плагина Tag-It
 * 
 * @category Phorm
 * @package JQuery_View_Helper
 * @name /Phorm/JQuery/View/Helper/TagIt.php
 * @copyright phorm.ru
 * @since 09.12.2012
 * @author vladimir@kachalov.net
 */

class Phorm_JQuery_View_Helper_TagIt extends ZendX_JQuery_View_Helper_UiWidget {
	
	public function tagIt($id, $value = null, array $params = array(), array $attribs = array()) {
		
		$attribs = $this->_prepareAttributes($id, $value, $attribs);
		
		$this->jquery->addJavascriptFile($this->view->BaseUrl().'/ui/tag-it/js/tag-it.min.js');
		$this->jquery->addStyleSheet($this->view->BaseUrl().'/ui/tag-it/css/jquery.tagit.css');
		
		$params = ZendX_JQuery::encodeJson($params);
		
		$js = sprintf('%s("#%s").tagit(%s);',
            ZendX_JQuery_View_Helper_JQuery::getJQueryHandler(),
            $attribs['id'],
            $params
        );
        $this->jquery->addOnLoad($js);
		
		return $this->view->formText($id, $value, $attribs);
		
	}
	
}